<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
  <title>扫码</title>
  <link rel="stylesheet" href="../css/common.css" />
  <style>
    .mask {
      height: 100%;
      width: 100%;
      position: absolute;
      top: 0;
      background: #ffffff;
    }
  </style>
</head>

<body>
<div class="mask" id="mask">

</div>
<script src="../config.js"></script>
<script src="../js/mui.min.js"></script>
<script type="text/javascript">
  mui.init()
  var scan;
  var userType;
  if(window.plus) {
    plusready();
  } else {
    document.addEventListener('plusready', plusready, false);
  }

  function plusready() {
    receiveParams()
    setTimeout(function() {
      scan = new plus.barcode.Barcode('mask');
      scan.start();
      scan.onmarked = function(type, result) {
        if(result) {
          scan.close();
          //strA[0] === '4'  首页扫码 核对奖品
          var strA = result.split('t=')[1].split('&d=')
          console.log(JSON.stringify(strA));
          if(strA[0]==='1'){
            var diamondTransferPage = plus.webview.getWebviewById('diamondTransfer');
            if(userType==='old'){
              mui.fire(diamondTransferPage,'oldUserIdDiamondTransfer',{
                userId:strA[1]
              })
            }else if(userType==='new'){
              mui.fire(diamondTransferPage,'newUserIdDiamondTransfer',{
                userId:strA[1]
              })
            }
            plus.webview.currentWebview().hide();
            plus.webview.currentWebview().close();

          }else{
            mui.toast('请出示会员二维码')
          }
        }
      };
    }, 200)
    //处理返回事件
    plus.key.addEventListener('backbutton', function() {
      plus.webview.currentWebview().hide();
      plus.webview.currentWebview().close();
    })
  }

  function receiveParams() {
    var self = plus.webview.currentWebview()

    userType = self.userType;
  }

</script>
</body>

</html>